home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / ANTENNA / YAGIU112 / LINEAR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-29  |  1.6 KB  |  43 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "yagi.h"
  4.  
  5. /* This function attemnts to optimise by setting the currents of the last N
  6. (user specifies N) directios to have the same magnitude of cureent. We do this
  7. by computing the currents in the last N directors, then finding the sd from the
  8. mean. Then we optimise to reduce the sd. We take as one argument the 'old_sd'
  9. . If we manage to reduce it, we change this value. */
  10.  
  11. int linear_current_optimisation_test(struct FCOMPLEX *cur, double *old_sd, int elements, int parasites, struct flags flag) 
  12. {
  13.     double mean, SD, current_on_this_element, sum_of_squares=0.0, total_I=0.0;
  14.     static double old_mean=0.0;
  15.     int total_elements_tested,k;
  16.     total_elements_tested=flag.Cflg; /* The user wants to test this number */
  17.     if(total_elements_tested > elements -1)
  18.     {
  19.         printf("We can only try to get the currents similar on the %d elements, and we dont have the %d elements that you requsted via the -C option\n", elements-1, flag.Cflg);
  20.         exit(1);
  21.     }
  22.     for(k=elements; k>elements-total_elements_tested; k--)
  23.     {
  24.         current_on_this_element=sqrt(cur[k].r*cur[k].r+cur[k].i*cur[k].i);
  25.         total_I+=current_on_this_element;
  26.     }
  27.     /* find the mean element current */
  28.     mean=total_I/(double)(total_elements_tested);
  29.     /* now find sum of the squares of the deviations form the mean */
  30.     for(k=elements; k>=elements-total_elements_tested; k--)
  31.     {
  32.         sum_of_squares+=pow(sqrt(cur[k].r*cur[k].r+cur[k].i*cur[k].i)-mean,2.0);
  33.     }
  34.     SD=sum_of_squares/(double) (elements-1);
  35.     if(SD <  *old_sd)
  36.     {
  37.         *old_sd=SD;
  38.         return(TRUE); /* currents are closer to being equal */
  39.     }
  40.     else
  41.         return(FALSE);
  42. }
  43.